package com.fire.control.system.module.system.service.impl;

import java.io.FileNotFoundException;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.fire.control.system.dto.AppManagerDto;
import com.fire.control.system.entity.File;
import com.fire.control.system.module.file.dao.FileMapper;
import com.fire.control.system.module.system.dao.AppManagerMapper;
import com.fire.control.system.module.system.service.AppManagerService;
import com.fire.control.system.support.protocol.comman.ResponseJsonProtocol;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.util.ResultPageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 
 * @ClassName: AppManagerServiceImpl
 * @Description: TODO(app升级管理)
 * @author: tanyuting
 * @date: 2017年7月1日 下午4:24:04
 */
@Service("AppService")
public class AppManagerServiceImpl implements AppManagerService {
	
	@Autowired private AppManagerMapper appManagerMapper;
   @Autowired private FileMapper filemapper;

	
   /*
    * (非 Javadoc)
   * Title: getAppManagerList
   * @Description: 获取app升级列表
   * @param dto
   * @param p
   * @return
   * @see com.fire.control.system.module.system.service.AppMapperService#getAppManagerList(com.fire.control.system.dto.AppManagerDto, org.springframework.data.domain.Pageable)
   * @author tangyiting
    */
	@Override
	public ResponseProtocol getAppManagerList(AppManagerDto dto) {	
	//	System.out.println(p.getPageSize()+"-----------------");
		PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
		String startTime = dto.getStartTime();
		if(StringUtils.isNotEmpty(startTime)){
			startTime+=" 00:00:00";
			dto.setStartTime(startTime);
		}
		String endTime = dto.getEndTime();
		if(StringUtils.isNotEmpty(endTime)){
			endTime+=" 23:59:59";
			dto.setEndTime(endTime);
		}
		List<AppManagerDto> list = appManagerMapper.getAppManagerList(dto);
		ResponseJsonProtocol protocol = new ResponseJsonProtocol();
		protocol.setData(ResultPageUtil.resultPage(new PageInfo<AppManagerDto>(list), list));
		return protocol;
	}

	

	/*
	 * (non Javadoc)
	 * @Title: addAppManager
	 * @Description: TODO   (app升级添加)
	 * @param appd
	 * @return
	 * @see com.fire.control.system.module.system.service.AppMapperService#addAppManager(com.fire.control.system.dto.AppManagerDto)
	  * @author: tanyuting
	 */
	@Override
	public ResponseProtocol addAppManager(AppManagerDto appd) {
	   appManagerMapper.addAppManager(appd);
	   return new ResponseJsonProtocol();
	}



	/*
	 * (non Javadoc)
	 * @Title: getappdownloadFile
	 * @Description: 文件下载
	 * @param appd
	 * @return
	 * @see com.fire.control.system.module.system.service.AppManagerService#getappdownloadFile(com.fire.control.system.dto.AppManagerDto)
	 *author:tanyuting
	 *@throws:FileNotFoundException 
	 */
	@Override 
	public File getappdownloadFile()throws FileNotFoundException {
		 
		return filemapper.getappdownloadFile();
    }



	/*
	 * (non Javadoc)
	 * @Title: updateAppManager
	 * @Description: TODO	修改app状态是否启用
	 * @param aid
	 * @return
	 * @see com.fire.control.system.module.system.service.AppManagerService#updateAppManager(java.lang.String)
	 *author:tanyuting
	 */
	@Override
	public ResponseProtocol enableAppManagerStatus(String aid) {
		appManagerMapper.displayAppManagerStatus();
		appManagerMapper.enableAppManagerStatus(aid);
		return new ResponseJsonProtocol();
	}



}
